/**
*This software is under LGPL license,
*see http://www.gnu.org/licenses/lgpl-3.0.txt (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>)
*Console.h First issued by chuanshenglu@gmail.com 2008.10
*/
#ifndef __CONSOLE_H__
#define __CONSOLE_H__

#include "trstd.h"
#include "Listener.h"
;
namespace TR{

	class Console{
	protected:
		//Data type definition;
		typedef enum{
			INSERT,
			REPLACE
		}InputMode;
		typedef enum{
			RED=1,
			GREEN=2,
			BLUE=4
		}ConsoleColor;

		InputMode mInputMode;
		Coord	mSize;
		String  mTitle;
		ConsoleColor  mBgColor;
		ConsoleColor  mForeColor;
		Coord	mCursorPos;
	public:
		typedef list<IKeyboardEventListener*>	KeyboardListenerList;
		typedef list<IFocusEventListener*>		FocusListenerList;
	protected:
		//Event Listener Lists
		KeyboardListenerList	mKeyboardListeners;
		FocusListenerList			mFocusListeners;
	public:
		//Public functions
		Console();
		Console(Console&);
		virtual ~Console();

		//never-return loop to handle events;
		virtual void EnterMainLoop()=0;

		//The detail of handling OS-related messages is left to the concret Consoles;
		//This one only provide a abstract interface;
		virtual void OnKeyboardEvent(KeyboardEvent)=0;
		virtual void OnFocusEvent(FocusEvent)=0;

		//But the Add/Remove listener routines are the same,so refined;
		//Manage the listener lists;
		virtual void AddKeyboardEventListener(IKeyboardEventListener*);
		virtual BOOL RemoveKeyboardEventListener(IKeyboardEventListener*);
		virtual void AddFocusEventListener(IFocusEventListener*);
		virtual BOOL RemoveFocusEventListener(IFocusEventListener*);

		//Important methods to manipulate the console screen;
		virtual BOOL WriteChar(Coord,TCHAR)=0;
		virtual BOOL WriteLine(Coord,const String&)=0;
		//virtual BOOL WriteBlock(
		virtual TCHAR GetChar(Coord)=0;
		virtual BOOL MoveCursor(Coord)=0;
		virtual void	ShowCursor(BOOL)=0;
		virtual Coord	GetCursorPos();
		virtual void  Resize(){}

		//Public gets and sets;
		virtual BOOL SetTitle(const String& str);
		virtual BOOL SetTitle(const TCHAR* str);
		virtual String& GetTitle();
		virtual uint32 GetWidth();
		virtual uint32 GetHeight();
		virtual InputMode GetInputMode();
	};
}

#endif
